package com.briup.smartlabs.web.controller;

import java.util.Date;
import java.util.List;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.format.annotation.DateTimeFormat.ISO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.briup.smartlabs.bean.SmartEnvDetail;
import com.briup.smartlabs.bean.ex.EnvStatisticData;
import com.briup.smartlabs.common.utils.Response;
import com.briup.smartlabs.service.SmartEnvService;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.github.pagehelper.PageInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

//统计模块
@Api(tags = "环境数据服务")
@RestController
@RequestMapping("/env")
public class SmartEnvController {
	
	@Autowired
	SmartEnvService envService;
	
	@ApiOperation(value = "按月统计(指定实验环境数据)")
	@GetMapping("/statistic/by/month")
	public Response<List<EnvStatisticData>> statisByMonth(String date){
		return Response.ok(envService.findByMonth(date));
	}
	
	@ApiOperation(value = "按年统计(指定实验环境数据)")
	@GetMapping("/statistic/by/year")
	public Response<List<EnvStatisticData>> statisByYear(String year){
		return Response.ok(envService.findByYear(year));
	}

	@ApiOperation("分页+条件查询所有环境信息值")
	@GetMapping("/detail/by/condition")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "pageNum", value = "当前页", dataType = "int", required = true, defaultValue = "1"),
			@ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "int", required = true, defaultValue = "5"),
			@ApiImplicitParam(name = "startTime", value = "开始时间",paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "type", value = "数据类型", paramType = "query", dataType = "String")
	})
	public Response<PageInfo<SmartEnvDetail>> findByCondition(Integer pageNum ,
																Integer pageSize,
															  	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date start,
															  	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date end,
																String type){
		PageInfo<SmartEnvDetail> page = envService.findAllByPage(pageNum, pageSize, start, end, type);
		return Response.ok(page);
	}


}





